/*
 * @Author: 哈尔滨大拐 3181845089@qq.com
 * @Date: 2022-08-08 10:56:32
 * @LastEditors: 哈尔滨大拐 3181845089@qq.com
 * @LastEditTime: 2022-08-08 11:02:32
 * @FilePath: \mygit\个人网站\admin\js\login.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
(function () {
    const username = document.querySelector("#username");
    const password = document.querySelector("#password");
    const btnLogin = document.querySelector("#btn-login");
    btnLogin.addEventListener(
      "click",
      () => {
        axios
          .post("/admin/login", {
            username: username.value,
            password: password.value,
          })
          .then((res) => {
            let { state, token } = res.data;
  
            if(state === "login_success"){
              localStorage.setItem("token", token);
              alert('登录成功');
              location.href = 'index.html';
            }
          });
      },
      false
    );
  })();
  